import { EggAppConfig, EggAppInfo, PowerPartial } from 'egg';

// IP 锁配置文件
const ipLookConfig = require('./ipLook');

export default (appInfo: EggAppInfo) => {
  const config = {} as PowerPartial<EggAppConfig>;

  config.mongoose = {
    client: {
      // url: 'mongodb://wang:0.123456@wx.wangyabin.top:27017/WangAdmin',
      url: 'mongodb://dev_user:dev_user123@10.100.163.73:27017/handbook',
      options: {
        useUnifiedTopology: true
      }
    },
  }

  // 引用部署在反向代理中
  config.proxy = true;

  // override config from framework / plugin
  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + '_1582613570676_1998';

  // add your egg config in here
  config.middleware = [
    // 'ipLook',
    'errorHandler',
    'tokenUpdate',
    'superAdmin'
  ];

  config.tokenUpdate = {
    match: /\/auth|\/super-auth/i,
  }

  config.superAdmin = {
    match: '/super-auth',
  }

  config.jwt = {
    secret: "Wang-Admin",
    match: /\/auth|\/super-auth/i,
  }

  config.token = {
    // 秒
    validTime: 2 * 3600
  }

  config.redis = {
    // client: {
    //   port: 6379,
    //   host: '127.0.0.1',
    //   password: '',
    //   db: 0,
    // },
    client: {
      cluster: true,
      nodes: [{
        host: '10.100.163.72',
        port: 6379,
        password: 'dev@hengda',
        db: 0,
      }, {
        host: '10.100.163.72',
        port: 6380,
        password: 'dev@hengda',
        db: 0,
      }, {
        host: '10.100.163.72',
        port: 7000,
        password: 'dev@hengda',
        db: 0,
      }, {
        host: '10.100.163.72',
        port: 7001,
        password: 'dev@hengda',
        db: 0,
      }, {
        host: '10.100.163.72',
        port: 7002,
        password: 'dev@hengda',
        db: 0,
      }, {
        host: '10.100.163.72',
        port: 7003,
        password: 'dev@hengda',
        db: 0,
      }, {
        host: '10.100.163.72',
        port: 7004,
        password: 'dev@hengda',
        db: 0,
      }, {
        host: '10.100.163.72',
        port: 7005,
        password: 'dev@hengda',
        db: 0,
      }, {
        host: '10.100.163.72',
        port: 7006,
        password: 'dev@hengda',
        db: 0,
      }]
    },
  };

  // add your special config in here
  const bizConfig = {
    sourceUrl: `https://github.com/eggjs/examples/tree/master/${appInfo.name}`,
    cluster: {
      listen: {
        port: 3004,
        // hostname: '127.0.0.1',
        hostname: '0.0.0.0'
      }
    }
  };

  // IP锁定
  config.fullIP = ipLookConfig;

  // the return config will combines to EggAppConfig
  return {
    ...config,
    ...bizConfig,
  };
};
